partnerHomeController = BaseController.extend({
	template:'partnerHome',
	center:'合伙人首页',
	bottomShow:true,
	mainView: 'partnerHome',
	goodsData:new ReactiveVar([]),
	goodsListData:new ReactiveVar([]),
	waitOn:function(){
		this.partner = this.currentUser();
		let self = this;
		if(typeof(this.partner.id) != 'undefined'){
			this.get('common/get-partner-goods',{partner_id:this.partner.id,level_name:this.partner.level_name,limit:5}).then(function(res){
				var arr = [];
				var data = res.data;
				for(var i in data){
					arr.push(data[i])
				}
				self.goodsData.set(arr);
			},function(err){
				console.log(err)
			})
		}
		
		var level_name = this.partner.level_name;
		if (level_name == 'monitor' && this.partner.id){
			Meteor.subscribe('classCodes',{partner_id: parseInt(this.partner.id)}, {});
		}else if ((level_name == 'company' || level_name == 'platoon') && this.partner.id){
				if(typeof(this.partner.id) != 'undefined'){
					this.get('common/get-plg',{partner_id:this.partner.id,level_name: level_name}).then(function(res){
						var arr = [];
						var data = res.data;
						for(var i in data){
							arr.push(data[i])
						}
						self.goodsListData.set(arr);
					},function(err){
						console.log(err)
					})
				}
		}

		Meteor.subscribe('draws',{partner_id:this.partner.id},{limit:5,sort:{id:-1}});
		Meteor.subscribe('wallets',{partner_id:this.partner.id},{});
	
	},
	onRendered:function(){
//		$('.x7-partnerHome-select').bind('click', function(e){
//				var id = e.currentTarget.id;
//				if ($("#id_"+id).css('display') == 'none'){
//					console.log('display is none');
//					$("#id_"+id).animate({display:'block',height: 'toggle', opacity: 'toggle'}, 500);
//					$('.x7-partnerHome-select').unbind('click');
//				}else {
//					console.log('display is block');					
//					$("#id_"+id).animate({display: 'none',height: 'toggle', opacity: 'toggle'}, 500);
//					$('.x7-partnerHome-select').unbind('click');
//				}
//			});
//		$('.x7-partnerHome-select').unbind('click', function(){
//			console.log('unbind click');
//		});
	},
	events: function(){
		let self = this;
		var timer = null;
		
		return {
			'click .x7-partnerHome-select': function(e){
				var id = e.currentTarget.id;
				if ($("#id_"+id).css('display') == 'none'){
					$("#id_"+id).css("display", "block");
				}else {
					$("#id_"+id).css("display", "none");
				}
			}
		};
	},
	data: function() {
		let self = this;
		return {
			partner:function(){
				var partner = self.partner;
				switch (self.partner.level_name){
					case 'company':
						partner.name_postfix = '(连长)';
						break;
					case 'platoon':
						partner.name_postfix = '(排长)';
						break;
					case 'monitor':
						partner.name_postfix = '(班长)';
						break;
					default:
						break;
				}
				return partner;
			},
			goodsData: function(){
				return self.goodsData.get();
			},
			draws: function(){
				return Draws.find().fetch();
			},
			have_draws: function(){
				return !isEmptyObject(Draws.findOne());	
			},
			wallets:function(){
				return Wallets.findOne();
			},
			my_team: function(){
				var level_name = self.partner.level_name;
				switch(level_name){
					case "company":
					case "platoon":
						return self.goodsListData.get();
						break;
					case "monitor":
						return ClassCodes.find().fetch();
						break;
					default:
						//return {};
				}
			},
			goods_menu: function(){	
				//return self.goodsListData.get();
			},
			isMonitor: function(){
				if (self.partner.level_name == 'monitor')
					return true;
				return false;
			},
		};
	}
})
